package com.example.TEvaluation.contorller;

import com.example.TEvaluation.service.AsyncService;
import com.example.TEvaluation.service.AsyncServiceImp;
import org.apache.tomcat.jni.Thread;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.Future;

//测试全局配置异常
@Controller
public class TestConterller {
    @Autowired
    private AsyncService asyncService;

    @RequestMapping("/test")
   /* @ResponseBody*/
    public String test(){
        int a=5/0;
        return "sfadfsdf";
    }
   @RequestMapping("/asyn")
   @ResponseBody
    public  String as() throws Exception{
        long start =System.currentTimeMillis();
       Future<String> task=asyncService.doTask();
       Future<String> task1=asyncService.doTask1();
       Future<String> task2=asyncService.doTask2();
       while (true){
           if (task.isDone()&&task1.isDone()&task2.isDone()){
              break;
           }
           java.lang.Thread.sleep(10000);
       }
       long end =System.currentTimeMillis();
        return "全部完成总耗时"+(end-start)+"毫秒"+(new Date(end));
    }
}
